package HotleManagement;

import java.util.Scanner;

public class Hotel {
    Room[][] rooms = new Room[4][6];

    //给rooms每个元素初始化 - 构造器
    public Hotel() {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 6; j++) {
                rooms[i][j] = new Room(i, j);
            }
        }
    }

    //查看房间信息
    public void show() {
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                System.out.print(rooms[i][j].num);
                System.out.print('\t');
            }
            System.out.println();
            for (int j = 0; j < rooms[i].length; j++) {
                System.out.print(rooms[i][j].have);
                System.out.print('\t');
            }
            System.out.println();
        }
    }

    // 查看客人信息
    public void check() {
        Scanner console = new Scanner(System.in);
        int count = 3;//一共3次机会
        while (true) {
            System.out.println("请输入管理员密码：");
            int code = console.nextInt();
            if (count > 0) {
                if (code == 1203) {
                    for (int i = 0; i < rooms.length; i++) {
                        for (int j = 0; j < rooms[i].length; j++) {
                            System.out.print(rooms[i][j].num);
                            System.out.print('\t');
                        }
                        System.out.println();
                        for (int j = 0; j < rooms[i].length; j++) {
                            System.out.print(rooms[i][j].guest.name);
                            System.out.print('\t');
                        }
                        System.out.println();
                    }
                    break;
                } else {
                    count--;
                    System.out.println("密码错误，还有" + count + "次机会！");
                    if (count <= 0) {
                        System.exit(0);
                    }
                }
            } else {
                System.exit(0);
            }
        }
    }

    //入住
    public void in() {
        Scanner console = new Scanner(System.in);
        while (true) {
            System.out.print("请输入房间号(退出请输入0):");
            int room = console.nextInt();
            if (room == 0) {
                System.exit(0);
            } else if ((room > 100 && room < 107) || (room > 200 && room < 207) || (room > 300 && room < 307) || (room > 400 && room < 407)) {
                int i = (room / 100) - 1;
                int j = (room % 100) - 1;
                if (this.rooms[i][j].guest.name.equals("空")) {
                    System.out.print("请输入您的姓名:");
                    console.nextLine();
                    String name = console.nextLine();
                    this.rooms[i][j].guest.name = name;
                    System.out.print("请输入您的身份证号:");
                    String code = console.nextLine();
                    this.rooms[i][j].guest.idCode = code;
                    this.rooms[i][j].have = "无";
                    System.out.println("入住成功！");
                    break;
                } else {
                    System.out.println(room + "号房间已有人入住，请重新输入房间号");
                }
            } else {
                System.out.println("请输入正确房间号");
            }
        }
    }

    //退房
    public void out() {
        Scanner console = new Scanner(System.in);
        while (true) {
            System.out.print("请输入房间号(退出请输入0):");
            int room = console.nextInt();
            if (room == 0) {
                System.exit(0);
            } else if ((room > 100 && room < 107) || (room > 200 && room < 207) || (room > 300 && room < 307) || (room > 400 && room < 407)) {
                int i = (room / 100) - 1;
                int j = (room % 100) - 1;
                if (this.rooms[i][j].guest.name.equals("空")) {
                    System.out.println("该房间无人入住，请输入正确房间号");
                } else {
                    this.rooms[i][j].guest.name = "空";
                    this.rooms[i][j].guest.idCode = "空";
                    this.rooms[i][j].have = "有";
                    System.out.println("退房成功！");
                    break;
                }
            } else {
                System.out.println("请输入正确房间号");
            }
        }
    }
}
